package ocr

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"hotgo/api/api/ocr/v1"
	"hotgo/internal/consts"
	"hotgo/internal/controller/api/recorder"
	"hotgo/internal/library/queue"
)

var (
	ctx = context.Background()
	//PaddleEnv string
)

//func init() {
//PaddleEnv = gfile.Join(os.Getenv("HOME"), "venvs/paddle_env/bin/paddleocr")
//if !gfile.Exists(PaddleEnv) {
//	g.Log().Error(ctx, "虚拟环境不存在")
//	return
//}
//g.Dump("init PaddleEnv")
//}

func (c *ControllerV1) ImagOcr(ctx context.Context, req *v1.ImagOcrReq) (res *v1.ImagOcrRes, err error) {
	g.Dump(333)
	g.Dump(queue.Push(consts.QueueRecorderOcrTopic, recorder.QueueRecorder{
		Path:       "/root/img/123.png",
		Regexp:     "[A-Z][0-9]{4}",
		CameraId:   9,
		ActivityId: 9,
		Frame:      88,
	}))
	return
	//PaddleEnv := "~/venvs/paddle_env/bin/paddleocr"
	//command := fmt.Sprintf(
	//	"%s --image_dir '%s' --lang en --show_log false",
	//	PaddleEnv,
	//	req.Img,
	//)
	//g.Dump(999, command)
	//command := "source ~/venvs/paddle_env/bin/activate && paddleocr --image_dir /root/img/" + req.Img + " --lang en --show_log false"
	//result, err := gproc.ShellExec(ctx, command)
	//g.Dump(3334, command, result)
	//if err != nil {
	//	return
	//}
	//match, _ := gregex.MatchAllString("[A-Z][0-9]{4}", result)
	//if len(match) == 0 {
	//	return
	//}
	//for _, v := range match {
	//	for _, vv := range v {
	//		g.Dump(vv)
	//	}
	//}

	//return &v1.ImagOcrRes{Res: result}, err
}
